import uuid
import datetime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy import Column, String, DateTime, Boolean, ForeignKey, UniqueConstraint, Text, BigInteger, Integer
from sqlalchemy.orm import relationship


Base = declarative_base()


def generate_uuid():
    return uuid.uuid4().hex


class History(Base):
    """搜索历史"""
    __tablename__ = 'history'
    id = Column(String, primary_key=True, default=generate_uuid, comment='主键ID')

    type = Column(String, nullable=False, comment='搜索类型 自定义搜索/点选搜索')
    configure = Column(JSONB, default={}, comment='搜索参数配置')
    created_at = Column(DateTime, default=datetime.datetime.utcnow, comment='创建时间')
    updated_at = Column(DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow, comment='更新时间')
